package com.suxin.plugin.listener;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Tang
 * @classname PluginListenerFactory
 * @description [  ]
 * @date 2022/6/26 22:41
 */
public class PluginListenerFactory implements PluginListener {

    private final List<PluginListener> listeners = new ArrayList<>();
    private final List<Class> listenerClasses = new ArrayList<>();

    @Override
    public void register(String pluginId) {
        for (PluginListener listener : listeners) {
            listener.register(pluginId);
        }
    }

    @Override
    public void unRegister(String pluginId) {

    }

    @Override
    public void failure(String pluginId, Throwable throwable) {
        for (PluginListener listener : listeners) {
            listener.failure(pluginId,throwable);
        }
    }

    public void addListener(PluginListener pluginListener) {
        if (pluginListener != null) {
            listeners.add(pluginListener);
        }
    }

    public void addListeners(List<PluginListener> pluginListeners) {
        if (pluginListeners != null) {
            listeners.addAll(pluginListeners);
        }
    }
}